package utils
{
	import flash.events.Event;
	import flash.net.FileFilter;
	import flash.net.FileReference;

	public class FileUtil
	{
		private static var _fileReference:FileReference = new FileReference();
		private static var respond:Function;
		
		public function FileUtil()
		{
		}
		
		public static function onLoadFile(f:Function):void
		{
			respond = f;
			var fileFilter:FileFilter = new FileFilter("*.mp3", "*.mp3");
			_fileReference.browse([fileFilter]);
			_fileReference.addEventListener(Event.SELECT, selectHandler);
		}
		
		protected static function selectHandler(event:Event):void
		{
			_fileReference.removeEventListener(Event.SELECT, selectHandler);
			_fileReference.addEventListener(Event.COMPLETE, loadCompleteHandler);
			_fileReference.load();
			
		}
		
		protected static function loadCompleteHandler(event:Event):void
		{
			respond.call("", _fileReference.data);
		}
		
	}
}